/**
 * 初始化字典
 */

layui.use(['jquery'], function() {
    if (!window.top.dictionary) {
        layui.$.ajax({
            url: "/dictionary.js?" + Date.now(),
            async: false,
            type: 'post',
            success: function (data) {
                window.top.dictonary = data;
            }
        });
    }
    layui.$.each(layui.$("select"),function ( index , node ){
        let dataKey = layui.$(node).attr("data-key");
        if (CommonUtil.isNotEmpty(dataKey)){
            let arr = dataKey.split(":");
            let data = window.top.dictonary ;
            let rows = data[arr[0]];
            let row = rows[arr[1]];
            for (let key in row){
                let dataValue = "";
                if (layui.$(node).attr("data-default-value") == key.toString()
                    || layui.$(node).attr("data-default-value") == row[key.toString()]){
                    dataValue = " selected ";
                }
                layui.$(node).append("<option value='"+key+"' "+ dataValue+">"+row[key.toString()]+"</option>");
            }
        }

    })
});
